home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / HyperXExamples / PExamples / Reduce.p < prev   
Encoding:
Text File  |  1998-12-03  |  1.1 KB  |  70 lines  |  [TEXT/MPS ]

  1. (*
  2.  *    Reduce    - XFCN to compress runs of spaces and tabs to a space
  3.  *                    - Fully MPW 3.0 compatible
  4.  *                    - written by Dan Allen
  5.  *
  6.  *    Sample HyperTalk line:
  7.  *
  8.  *    put reduce(field 1) into field 1 -- reduce tabs & spaces
  9.  *
  10.  *)
  11.  
  12. {$R-}
  13. {$Z+} (* has to have this or else put EntryPoint in Interface section *)
  14.  
  15. UNIT DummyUnit;
  16.  
  17.  
  18. INTERFACE
  19.  
  20. USES
  21.     Types,
  22.     Memory,
  23.     HyperXCmd;
  24.  
  25.  
  26. IMPLEMENTATION
  27.  
  28.  
  29. PROCEDURE MoveHHiTrap(h: Handle); INLINE $205F, $A064;
  30.  
  31.  
  32. PROCEDURE EntryPoint(paramPtr: XCmdPtr);
  33. CONST
  34.     tab = 9;
  35.     space = 32;
  36. VAR
  37.     h:         Handle;        
  38.     p,q:    Ptr;
  39.  
  40. BEGIN
  41.     WITH paramPtr^ DO
  42.         BEGIN
  43.             IF paramCount <> 1 THEN EXIT(EntryPoint);
  44.             MoveHHiTrap(params[1]);
  45.             h := NewHandle(GetHandleSize(params[1]));
  46.             IF h = NIL THEN EXIT(EntryPoint);
  47.             p := params[1]^;
  48.             q := h^;
  49.             WHILE p^ <> 0 DO
  50.                 IF (p^ = tab) OR (p^ = space) THEN
  51.                     BEGIN
  52.                         REPEAT
  53.                             p := POINTER(ORD(p)+1);
  54.                         UNTIL (p^ <> tab) AND (p^ <> space);
  55.                         q^ := space;
  56.                         q := POINTER(ORD(q)+1);
  57.                     END
  58.                 ELSE
  59.                     BEGIN
  60.                         q^ := p^;
  61.                         p := POINTER(ORD(p)+1);
  62.                         q := POINTER(ORD(q)+1);
  63.                     END;
  64.             q^ := 0;
  65.             returnValue := h;
  66.         END; { with }
  67. END; { procedure }
  68.  
  69. END. { unit }
  70.